import {createSlice} from "@reduxjs/toolkit";
import axios from "axios";
const goodsSlice = createSlice({
    name:"goods",
    initialState:{
        goodsList:[]
    },
    reducers:{
        addGoods(state,{payload}){
            state.goodsList = [
                ...state.goodsList,
                payload
            ]
        },
        upGoodsList(state,{payload}){
            state.goodsList = payload
        }
    }
});
const {upGoodsList} = goodsSlice.actions;
export const asyncGetGoodsList = function(){
    return async function(dispatch,getState){
        const {data} = await axios.get("/data.json");
        dispatch(upGoodsList(data.goodsList));
        return getState();
    }
}
export default goodsSlice.reducer;